{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "0joqdbKedFtm"
   },
   "source": [
    "<a href=\"https://colab.research.google.com/github/jeffheaton/t81_558_deep_learning/blob/master/t81_558_class_07_5_tabular_synthetic.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "Or3fhGk9dFtn"
   },
   "source": [
    "# T81-558: Applications of Deep Neural Networks\n",
    "**Module 7: Generative Adversarial Networks**\n",
    "* Instructor: [Jeff Heaton](https://sites.wustl.edu/jeffheaton/), McKelvey School of Engineering, [Washington University in St. Louis](https://engineering.wustl.edu/Programs/Pages/default.aspx)\n",
    "* For more information visit the [class website](https://sites.wustl.edu/jeffheaton/t81-558/)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "W-QArqZxdFto"
   },
   "source": [
    "# Module 7 Material\n",
    "\n",
    "* Part 7.1: Introduction to GANs for Image and Data Generation [[Video]](https://www.youtube.com/watch?v=hZw-AjbdN5k&list=PLjy4p-07OYzulelvJ5KVaT2pDlxivl_BN) [[Notebook]](https://github.com/jeffheaton/t81_558_deep_learning/blob/master/t81_558_class_07_1_gan_intro.ipynb)\n",
    "* Part 7.2: Train StyleGAN3 with your Own Images [[Video]](https://www.youtube.com/watch?v=R546LYsQk5M&list=PLjy4p-07OYzulelvJ5KVaT2pDlxivl_BN) [[Notebook]](https://github.com/jeffheaton/t81_558_deep_learning/blob/master/t81_558_class_07_2_train_gan.ipynb)\n",
    "* Part 7.3: Exploring the StyleGAN Latent Vector [[Video]](https://www.youtube.com/watch?v=goQzp8QSb2s&list=PLjy4p-07OYzulelvJ5KVaT2pDlxivl_BN) [[Notebook]](https://github.com/jeffheaton/t81_558_deep_learning/blob/master/t81_558_class_07_3_latent_vector.ipynb)\n",
    "* Part 7.4: GANs to Enhance Old Photographs Deoldify [[Video]](https://www.youtube.com/watch?v=0OTd5GlHRx4&list=PLjy4p-07OYzulelvJ5KVaT2pDlxivl_BN) [[Notebook]](https://github.com/jeffheaton/t81_558_deep_learning/blob/master/t81_558_class_07_4_deoldify.ipynb)\n",
    "* **Part 7.5: GANs for Tabular Synthetic Data Generation** [[Video]](https://www.youtube.com/watch?v=yujdA46HKwA&list=PLjy4p-07OYzulelvJ5KVaT2pDlxivl_BN) [[Notebook]](https://github.com/jeffheaton/t81_558_deep_learning/blob/master/t81_558_class_07_5_tabular_synthetic.ipynb)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "Zn-FViihdN1M"
   },
   "source": [
    "# Google CoLab Instructions\n",
    "\n",
    "The following code ensures that Google CoLab is running the correct version of TensorFlow.\n",
    "  Running the following code will map your GDrive to ```/content/drive```."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "f7G_GEwHdOrE",
    "outputId": "020e24de-efe3-4b95-88aa-03430c473cfa"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Note: using Google CoLab\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    from google.colab import drive\n",
    "    COLAB = True\n",
    "    print(\"Note: using Google CoLab\")\n",
    "    %tensorflow_version 2.x\n",
    "except:\n",
    "    print(\"Note: not using Google CoLab\")\n",
    "    COLAB = False"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "aCb4iUtAdFto"
   },
   "source": [
    "# Part 7.5: GANs for Tabular Synthetic Data Generation\n",
    "\n",
    "Typically GANs are used to generate images. However, we can also generate tabular data from a GAN. In this part, we will use the Python tabgan utility to create fake data from tabular data. Specifically, we will use the Auto MPG dataset to train a GAN to generate fake cars.  [Cite:ashrapov2020tabular](https://arxiv.org/pdf/2010.00638.pdf)\n",
    "\n",
    "## Installing Tabgan\n",
    "\n",
    "Pytorch is the foundation of the tabgan neural network utility. The following code installs the needed software to run tabgan in Google Colab. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "5-iTPkSWdsGa",
    "outputId": "bfd5ee3e-feb9-4a40-c5ad-3540ae4f8350"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--2022-04-03 18:53:04--  https://raw.githubusercontent.com/Diyago/GAN-for-tabular-data/master/requirements.txt\n",
      "Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.108.133, 185.199.109.133, 185.199.110.133, ...\n",
      "Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.108.133|:443... connected.\n",
      "HTTP request sent, awaiting response... 200 OK\n",
      "Length: 197 [text/plain]\n",
      "Saving to: ‘requirements.txt.1’\n",
      "\n",
      "requirements.txt.1  100%[===================>]     197  --.-KB/s    in 0s      \n",
      "\n",
      "2022-04-03 18:53:04 (8.18 MB/s) - ‘requirements.txt.1’ saved [197/197]\n",
      "\n",
      "Requirement already satisfied: scipy==1.4.1 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 1)) (1.4.1)\n",
      "Requirement already satisfied: category_encoders==2.1.0 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 2)) (2.1.0)\n",
      "Requirement already satisfied: numpy==1.18.1 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 3)) (1.18.1)\n",
      "Requirement already satisfied: torch==1.6.0 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 4)) (1.6.0)\n",
      "Requirement already satisfied: pandas==1.2.2 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 5)) (1.2.2)\n",
      "Requirement already satisfied: lightgbm==2.3.1 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 6)) (2.3.1)\n",
      "Requirement already satisfied: scikit_learn==0.23.2 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 7)) (0.23.2)\n",
      "Requirement already satisfied: torchvision>=0.4.2 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 8)) (0.7.0)\n",
      "Requirement already satisfied: python-dateutil==2.8.1 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 11)) (2.8.1)\n",
      "Requirement already satisfied: tqdm==4.61.1 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 12)) (4.61.1)\n",
      "Requirement already satisfied: patsy>=0.4.1 in /usr/local/lib/python3.7/dist-packages (from category_encoders==2.1.0->-r requirements.txt (line 2)) (0.5.2)\n",
      "Requirement already satisfied: statsmodels>=0.6.1 in /usr/local/lib/python3.7/dist-packages (from category_encoders==2.1.0->-r requirements.txt (line 2)) (0.10.2)\n",
      "Requirement already satisfied: future in /usr/local/lib/python3.7/dist-packages (from torch==1.6.0->-r requirements.txt (line 4)) (0.16.0)\n",
      "Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.7/dist-packages (from pandas==1.2.2->-r requirements.txt (line 5)) (2018.9)\n",
      "Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from scikit_learn==0.23.2->-r requirements.txt (line 7)) (3.1.0)\n",
      "Requirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.7/dist-packages (from scikit_learn==0.23.2->-r requirements.txt (line 7)) (1.1.0)\n",
      "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil==2.8.1->-r requirements.txt (line 11)) (1.15.0)\n",
      "Requirement already satisfied: pillow>=4.1.1 in /usr/local/lib/python3.7/dist-packages (from torchvision>=0.4.2->-r requirements.txt (line 8)) (7.1.2)\n",
      "Requirement already satisfied: tabgan in /usr/local/lib/python3.7/dist-packages (1.2.0)\n",
      "Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from tabgan) (1.18.1)\n",
      "Requirement already satisfied: pandas in /usr/local/lib/python3.7/dist-packages (from tabgan) (1.2.2)\n",
      "Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from tabgan) (4.61.1)\n",
      "Requirement already satisfied: scikit-learn==0.23.2 in /usr/local/lib/python3.7/dist-packages (from tabgan) (0.23.2)\n",
      "Requirement already satisfied: python-dateutil in /usr/local/lib/python3.7/dist-packages (from tabgan) (2.8.1)\n",
      "Requirement already satisfied: category-encoders in /usr/local/lib/python3.7/dist-packages (from tabgan) (2.1.0)\n",
      "Requirement already satisfied: lightgbm in /usr/local/lib/python3.7/dist-packages (from tabgan) (2.3.1)\n",
      "Requirement already satisfied: torchvision in /usr/local/lib/python3.7/dist-packages (from tabgan) (0.7.0)\n",
      "Requirement already satisfied: torch in /usr/local/lib/python3.7/dist-packages (from tabgan) (1.6.0)\n",
      "Requirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.7/dist-packages (from scikit-learn==0.23.2->tabgan) (1.1.0)\n",
      "Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from scikit-learn==0.23.2->tabgan) (3.1.0)\n",
      "Requirement already satisfied: scipy>=0.19.1 in /usr/local/lib/python3.7/dist-packages (from scikit-learn==0.23.2->tabgan) (1.4.1)\n",
      "Requirement already satisfied: patsy>=0.4.1 in /usr/local/lib/python3.7/dist-packages (from category-encoders->tabgan) (0.5.2)\n",
      "Requirement already satisfied: statsmodels>=0.6.1 in /usr/local/lib/python3.7/dist-packages (from category-encoders->tabgan) (0.10.2)\n",
      "Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.7/dist-packages (from pandas->tabgan) (2018.9)\n",
      "Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from patsy>=0.4.1->category-encoders->tabgan) (1.15.0)\n",
      "Requirement already satisfied: future in /usr/local/lib/python3.7/dist-packages (from torch->tabgan) (0.16.0)\n",
      "Requirement already satisfied: pillow>=4.1.1 in /usr/local/lib/python3.7/dist-packages (from torchvision->tabgan) (7.1.2)\n"
     ]
    }
   ],
   "source": [
    "# HIDE OUTPUT\n",
    "CMD = \"wget https://raw.githubusercontent.com/Diyago/\"\\\n",
    "  \"GAN-for-tabular-data/master/requirements.txt\"\n",
    "\n",
    "!{CMD}\n",
    "!pip install -r requirements.txt\n",
    "!pip install tabgan"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "HlETatByeGqz"
   },
   "source": [
    "Note, after installing; you may see this message:\n",
    "\n",
    "* You must restart the runtime in order to use newly installed versions.\n",
    "\n",
    "If so, click the \"restart runtime\" button just under the message. Then rerun this notebook, and you should not receive further issues.\n",
    "\n",
    "## Loading the Auto MPG Data and Training a Neural Network\n",
    "\n",
    "We will begin by generating fake data for the Auto MPG dataset we have previously seen. The tabgan library can generate categorical (textual) and continuous (numeric) data. However, it cannot generate unstructured data, such as the name of the automobile. Car names, such as \"AMC Rebel SST\" cannot be replicated by the GAN, because every row has a different car name; it is a textual but non-categorical value. \n",
    "\n",
    "The following code is similar to what we have seen before. We load the AutoMPG dataset. The tabgan library requires Pandas dataframe to train. Because of this, we keep both the Pandas and Numpy values."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "-YRAjvvMeWuz",
    "outputId": "d819599f-8023-434c-fa9a-fd8df6935132"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/1000\n",
      "10/10 - 1s - loss: 139176.5625 - val_loss: 40689.0703 - 1s/epoch - 148ms/step\n",
      "Epoch 2/1000\n",
      "10/10 - 0s - loss: 19372.2285 - val_loss: 3346.7378 - 108ms/epoch - 11ms/step\n",
      "Epoch 3/1000\n",
      "10/10 - 0s - loss: 873.7932 - val_loss: 769.1017 - 109ms/epoch - 11ms/step\n",
      "Epoch 4/1000\n",
      "10/10 - 0s - loss: 1485.8730 - val_loss: 1525.9556 - 136ms/epoch - 14ms/step\n",
      "Epoch 5/1000\n",
      "10/10 - 0s - loss: 866.6918 - val_loss: 195.6039 - 155ms/epoch - 15ms/step\n",
      "Epoch 6/1000\n",
      "10/10 - 0s - loss: 142.9136 - val_loss: 177.2400 - 96ms/epoch - 10ms/step\n",
      "Epoch 7/1000\n",
      "10/10 - 0s - loss: 193.9373 - val_loss: 142.7312 - 113ms/epoch - 11ms/step\n",
      "Epoch 8/1000\n",
      "10/10 - 0s - loss: 116.1862 - val_loss: 89.0451 - 79ms/epoch - 8ms/step\n",
      "Epoch 9/1000\n",
      "10/10 - 0s - loss: 106.6868 - val_loss: 95.9191 - 174ms/epoch - 17ms/step\n",
      "Epoch 10/1000\n",
      "10/10 - 0s - loss: 104.5894 - val_loss: 87.7888 - 111ms/epoch - 11ms/step\n",
      "Epoch 11/1000\n",
      "10/10 - 0s - loss: 100.0589 - val_loss: 88.2749 - 96ms/epoch - 10ms/step\n",
      "Epoch 12/1000\n",
      "10/10 - 0s - loss: 99.6257 - val_loss: 87.3040 - 115ms/epoch - 11ms/step\n",
      "Epoch 13/1000\n",
      "10/10 - 0s - loss: 99.4177 - val_loss: 86.6027 - 103ms/epoch - 10ms/step\n",
      "Epoch 14/1000\n",
      "10/10 - 0s - loss: 98.5141 - val_loss: 86.1316 - 97ms/epoch - 10ms/step\n",
      "Epoch 15/1000\n",
      "10/10 - 0s - loss: 98.0732 - val_loss: 85.9742 - 108ms/epoch - 11ms/step\n",
      "Epoch 16/1000\n",
      "10/10 - 0s - loss: 97.4856 - val_loss: 85.1393 - 76ms/epoch - 8ms/step\n",
      "Epoch 17/1000\n",
      "10/10 - 0s - loss: 97.1630 - val_loss: 84.7279 - 85ms/epoch - 8ms/step\n",
      "Epoch 18/1000\n",
      "10/10 - 0s - loss: 96.7964 - val_loss: 84.2021 - 160ms/epoch - 16ms/step\n",
      "Epoch 19/1000\n",
      "10/10 - 0s - loss: 96.3048 - val_loss: 83.9871 - 92ms/epoch - 9ms/step\n",
      "Epoch 20/1000\n",
      "10/10 - 0s - loss: 95.4462 - val_loss: 83.0952 - 121ms/epoch - 12ms/step\n",
      "Epoch 21/1000\n",
      "10/10 - 0s - loss: 94.9444 - val_loss: 82.6417 - 91ms/epoch - 9ms/step\n",
      "Epoch 22/1000\n",
      "10/10 - 0s - loss: 94.3362 - val_loss: 82.0355 - 132ms/epoch - 13ms/step\n",
      "Epoch 23/1000\n",
      "10/10 - 0s - loss: 93.8082 - val_loss: 81.6199 - 89ms/epoch - 9ms/step\n",
      "Epoch 24/1000\n",
      "10/10 - 0s - loss: 93.2513 - val_loss: 81.1020 - 82ms/epoch - 8ms/step\n",
      "Epoch 25/1000\n",
      "10/10 - 0s - loss: 92.6264 - val_loss: 80.3359 - 121ms/epoch - 12ms/step\n",
      "Epoch 26/1000\n",
      "10/10 - 0s - loss: 92.2328 - val_loss: 79.8444 - 121ms/epoch - 12ms/step\n",
      "Epoch 27/1000\n",
      "10/10 - 0s - loss: 91.4926 - val_loss: 79.1404 - 109ms/epoch - 11ms/step\n",
      "Epoch 28/1000\n",
      "10/10 - 0s - loss: 90.7999 - val_loss: 78.6531 - 118ms/epoch - 12ms/step\n",
      "Epoch 29/1000\n",
      "10/10 - 0s - loss: 90.1882 - val_loss: 78.1106 - 112ms/epoch - 11ms/step\n",
      "Epoch 30/1000\n",
      "10/10 - 0s - loss: 89.8745 - val_loss: 77.8685 - 116ms/epoch - 12ms/step\n",
      "Epoch 31/1000\n",
      "10/10 - 0s - loss: 89.4765 - val_loss: 76.8118 - 94ms/epoch - 9ms/step\n",
      "Epoch 32/1000\n",
      "10/10 - 0s - loss: 88.4912 - val_loss: 76.5078 - 87ms/epoch - 9ms/step\n",
      "Epoch 33/1000\n",
      "10/10 - 0s - loss: 88.0864 - val_loss: 75.5026 - 102ms/epoch - 10ms/step\n",
      "Epoch 34/1000\n",
      "10/10 - 0s - loss: 86.9415 - val_loss: 75.0887 - 90ms/epoch - 9ms/step\n",
      "Epoch 35/1000\n",
      "10/10 - 0s - loss: 86.7026 - val_loss: 74.8265 - 129ms/epoch - 13ms/step\n",
      "Epoch 36/1000\n",
      "10/10 - 0s - loss: 86.5384 - val_loss: 73.6916 - 97ms/epoch - 10ms/step\n",
      "Epoch 37/1000\n",
      "10/10 - 0s - loss: 85.6226 - val_loss: 73.5788 - 105ms/epoch - 11ms/step\n",
      "Epoch 38/1000\n",
      "10/10 - 0s - loss: 84.6683 - val_loss: 72.4751 - 91ms/epoch - 9ms/step\n",
      "Epoch 39/1000\n",
      "10/10 - 0s - loss: 83.8491 - val_loss: 71.7716 - 90ms/epoch - 9ms/step\n",
      "Epoch 40/1000\n",
      "10/10 - 0s - loss: 83.1613 - val_loss: 71.0936 - 119ms/epoch - 12ms/step\n",
      "Epoch 41/1000\n",
      "10/10 - 0s - loss: 82.5631 - val_loss: 70.6658 - 89ms/epoch - 9ms/step\n",
      "Epoch 42/1000\n",
      "10/10 - 0s - loss: 81.8695 - val_loss: 69.8167 - 163ms/epoch - 16ms/step\n",
      "Epoch 43/1000\n",
      "10/10 - 0s - loss: 81.1869 - val_loss: 69.2964 - 91ms/epoch - 9ms/step\n",
      "Epoch 44/1000\n",
      "10/10 - 0s - loss: 80.8101 - val_loss: 68.9843 - 88ms/epoch - 9ms/step\n",
      "Epoch 45/1000\n",
      "10/10 - 0s - loss: 80.6469 - val_loss: 67.9292 - 143ms/epoch - 14ms/step\n",
      "Epoch 46/1000\n",
      "10/10 - 0s - loss: 79.4096 - val_loss: 67.6057 - 102ms/epoch - 10ms/step\n",
      "Epoch 47/1000\n",
      "10/10 - 0s - loss: 78.5745 - val_loss: 66.5229 - 69ms/epoch - 7ms/step\n",
      "Epoch 48/1000\n",
      "10/10 - 0s - loss: 78.8939 - val_loss: 66.6657 - 95ms/epoch - 10ms/step\n",
      "Epoch 49/1000\n",
      "10/10 - 0s - loss: 76.9754 - val_loss: 65.2553 - 106ms/epoch - 11ms/step\n",
      "Epoch 50/1000\n",
      "10/10 - 0s - loss: 76.6228 - val_loss: 64.6849 - 81ms/epoch - 8ms/step\n",
      "Epoch 51/1000\n",
      "10/10 - 0s - loss: 76.0204 - val_loss: 64.7692 - 120ms/epoch - 12ms/step\n",
      "Epoch 52/1000\n",
      "10/10 - 0s - loss: 74.8868 - val_loss: 63.3094 - 119ms/epoch - 12ms/step\n",
      "Epoch 53/1000\n",
      "10/10 - 0s - loss: 74.4092 - val_loss: 62.8904 - 136ms/epoch - 14ms/step\n",
      "Epoch 54/1000\n",
      "10/10 - 0s - loss: 73.6486 - val_loss: 62.5721 - 98ms/epoch - 10ms/step\n",
      "Epoch 55/1000\n",
      "10/10 - 0s - loss: 72.7242 - val_loss: 61.3689 - 131ms/epoch - 13ms/step\n",
      "Epoch 56/1000\n",
      "10/10 - 0s - loss: 72.2849 - val_loss: 61.0335 - 120ms/epoch - 12ms/step\n",
      "Epoch 57/1000\n",
      "10/10 - 0s - loss: 72.1777 - val_loss: 60.2657 - 163ms/epoch - 16ms/step\n",
      "Epoch 58/1000\n",
      "10/10 - 0s - loss: 71.7879 - val_loss: 59.4650 - 127ms/epoch - 13ms/step\n",
      "Epoch 59/1000\n",
      "10/10 - 0s - loss: 71.8203 - val_loss: 60.6488 - 83ms/epoch - 8ms/step\n",
      "Epoch 60/1000\n",
      "10/10 - 0s - loss: 69.9323 - val_loss: 58.5242 - 135ms/epoch - 13ms/step\n",
      "Epoch 61/1000\n",
      "10/10 - 0s - loss: 70.4658 - val_loss: 58.6250 - 153ms/epoch - 15ms/step\n",
      "Epoch 62/1000\n",
      "10/10 - 0s - loss: 68.6058 - val_loss: 57.0953 - 202ms/epoch - 20ms/step\n",
      "Epoch 63/1000\n",
      "10/10 - 0s - loss: 67.7657 - val_loss: 56.8579 - 110ms/epoch - 11ms/step\n",
      "Epoch 64/1000\n",
      "10/10 - 0s - loss: 67.2709 - val_loss: 56.0743 - 134ms/epoch - 13ms/step\n",
      "Epoch 65/1000\n",
      "10/10 - 0s - loss: 66.5735 - val_loss: 55.5872 - 115ms/epoch - 12ms/step\n",
      "Epoch 66/1000\n",
      "10/10 - 0s - loss: 66.1336 - val_loss: 54.8934 - 84ms/epoch - 8ms/step\n",
      "Epoch 67/1000\n",
      "10/10 - 0s - loss: 65.7582 - val_loss: 54.4984 - 142ms/epoch - 14ms/step\n",
      "Epoch 68/1000\n",
      "10/10 - 0s - loss: 65.1338 - val_loss: 53.6615 - 151ms/epoch - 15ms/step\n",
      "Epoch 69/1000\n",
      "10/10 - 0s - loss: 63.7764 - val_loss: 54.1908 - 107ms/epoch - 11ms/step\n",
      "Epoch 70/1000\n",
      "10/10 - 0s - loss: 63.6102 - val_loss: 52.6200 - 88ms/epoch - 9ms/step\n",
      "Epoch 71/1000\n",
      "10/10 - 0s - loss: 62.9163 - val_loss: 52.3956 - 92ms/epoch - 9ms/step\n",
      "Epoch 72/1000\n",
      "10/10 - 0s - loss: 62.3272 - val_loss: 51.6602 - 99ms/epoch - 10ms/step\n",
      "Epoch 73/1000\n",
      "10/10 - 0s - loss: 63.4992 - val_loss: 51.2628 - 161ms/epoch - 16ms/step\n",
      "Epoch 74/1000\n",
      "10/10 - 0s - loss: 62.8709 - val_loss: 50.4873 - 111ms/epoch - 11ms/step\n",
      "Epoch 75/1000\n",
      "10/10 - 0s - loss: 60.9686 - val_loss: 51.4177 - 82ms/epoch - 8ms/step\n",
      "Epoch 76/1000\n",
      "10/10 - 0s - loss: 59.7037 - val_loss: 49.4762 - 89ms/epoch - 9ms/step\n",
      "Epoch 77/1000\n",
      "10/10 - 0s - loss: 59.5827 - val_loss: 49.6083 - 121ms/epoch - 12ms/step\n",
      "Epoch 78/1000\n",
      "10/10 - 0s - loss: 59.7795 - val_loss: 48.5477 - 115ms/epoch - 11ms/step\n",
      "Epoch 79/1000\n",
      "10/10 - 0s - loss: 58.4787 - val_loss: 48.2142 - 113ms/epoch - 11ms/step\n",
      "Epoch 80/1000\n",
      "10/10 - 0s - loss: 58.1287 - val_loss: 48.3080 - 93ms/epoch - 9ms/step\n",
      "Epoch 81/1000\n",
      "10/10 - 0s - loss: 57.5325 - val_loss: 47.2556 - 77ms/epoch - 8ms/step\n",
      "Epoch 82/1000\n",
      "10/10 - 0s - loss: 56.7754 - val_loss: 47.1473 - 109ms/epoch - 11ms/step\n",
      "Epoch 83/1000\n",
      "10/10 - 0s - loss: 56.4003 - val_loss: 46.8065 - 101ms/epoch - 10ms/step\n",
      "Epoch 84/1000\n",
      "10/10 - 0s - loss: 56.7061 - val_loss: 45.9990 - 185ms/epoch - 18ms/step\n",
      "Epoch 85/1000\n",
      "10/10 - 0s - loss: 56.1603 - val_loss: 45.8791 - 197ms/epoch - 20ms/step\n",
      "Epoch 86/1000\n",
      "10/10 - 0s - loss: 55.1062 - val_loss: 45.0677 - 126ms/epoch - 13ms/step\n",
      "Epoch 87/1000\n",
      "10/10 - 0s - loss: 54.8889 - val_loss: 44.7583 - 120ms/epoch - 12ms/step\n",
      "Epoch 88/1000\n",
      "10/10 - 0s - loss: 54.1313 - val_loss: 44.8168 - 82ms/epoch - 8ms/step\n",
      "Epoch 89/1000\n",
      "10/10 - 0s - loss: 53.5392 - val_loss: 44.2517 - 76ms/epoch - 8ms/step\n",
      "Epoch 90/1000\n",
      "10/10 - 0s - loss: 53.6703 - val_loss: 44.3647 - 86ms/epoch - 9ms/step\n",
      "Epoch 91/1000\n",
      "10/10 - 0s - loss: 53.1194 - val_loss: 43.2339 - 164ms/epoch - 16ms/step\n",
      "Epoch 92/1000\n",
      "10/10 - 0s - loss: 52.4162 - val_loss: 43.0597 - 115ms/epoch - 12ms/step\n",
      "Epoch 93/1000\n",
      "10/10 - 0s - loss: 52.0441 - val_loss: 42.6480 - 83ms/epoch - 8ms/step\n",
      "Epoch 94/1000\n",
      "10/10 - 0s - loss: 51.5989 - val_loss: 42.4377 - 42ms/epoch - 4ms/step\n",
      "Epoch 95/1000\n",
      "10/10 - 0s - loss: 51.3697 - val_loss: 41.9103 - 48ms/epoch - 5ms/step\n",
      "Epoch 96/1000\n",
      "10/10 - 0s - loss: 51.3203 - val_loss: 41.6717 - 55ms/epoch - 6ms/step\n",
      "Epoch 97/1000\n",
      "10/10 - 0s - loss: 51.1632 - val_loss: 41.1382 - 65ms/epoch - 7ms/step\n",
      "Epoch 98/1000\n",
      "10/10 - 0s - loss: 50.2788 - val_loss: 40.7239 - 47ms/epoch - 5ms/step\n",
      "Epoch 99/1000\n",
      "10/10 - 0s - loss: 49.7021 - val_loss: 40.8461 - 50ms/epoch - 5ms/step\n",
      "Epoch 100/1000\n",
      "10/10 - 0s - loss: 50.6249 - val_loss: 40.8916 - 67ms/epoch - 7ms/step\n",
      "Epoch 101/1000\n",
      "10/10 - 0s - loss: 49.9470 - val_loss: 40.2612 - 47ms/epoch - 5ms/step\n",
      "Epoch 102/1000\n",
      "10/10 - 0s - loss: 49.3327 - val_loss: 39.3642 - 53ms/epoch - 5ms/step\n",
      "Epoch 103/1000\n",
      "10/10 - 0s - loss: 49.4299 - val_loss: 39.4563 - 67ms/epoch - 7ms/step\n",
      "Epoch 104/1000\n",
      "10/10 - 0s - loss: 48.4410 - val_loss: 39.5185 - 44ms/epoch - 4ms/step\n",
      "Epoch 105/1000\n",
      "10/10 - 0s - loss: 47.7434 - val_loss: 39.1029 - 49ms/epoch - 5ms/step\n",
      "Epoch 106/1000\n",
      "10/10 - 0s - loss: 47.3096 - val_loss: 38.3037 - 64ms/epoch - 6ms/step\n",
      "Epoch 107/1000\n",
      "10/10 - 0s - loss: 47.3403 - val_loss: 38.1661 - 50ms/epoch - 5ms/step\n",
      "Epoch 108/1000\n",
      "10/10 - 0s - loss: 47.3158 - val_loss: 39.3938 - 44ms/epoch - 4ms/step\n",
      "Epoch 109/1000\n",
      "10/10 - 0s - loss: 47.2465 - val_loss: 37.4724 - 63ms/epoch - 6ms/step\n",
      "Epoch 110/1000\n",
      "10/10 - 0s - loss: 46.1793 - val_loss: 38.2548 - 46ms/epoch - 5ms/step\n",
      "Epoch 111/1000\n",
      "10/10 - 0s - loss: 45.9742 - val_loss: 37.9052 - 48ms/epoch - 5ms/step\n",
      "Epoch 112/1000\n",
      "10/10 - 0s - loss: 46.8534 - val_loss: 36.6737 - 51ms/epoch - 5ms/step\n",
      "Epoch 113/1000\n",
      "10/10 - 0s - loss: 45.6568 - val_loss: 37.2436 - 43ms/epoch - 4ms/step\n",
      "Epoch 114/1000\n",
      "10/10 - 0s - loss: 46.1722 - val_loss: 37.9826 - 59ms/epoch - 6ms/step\n",
      "Epoch 115/1000\n",
      "10/10 - 0s - loss: 45.0864 - val_loss: 36.1506 - 45ms/epoch - 5ms/step\n",
      "Epoch 116/1000\n",
      "10/10 - 0s - loss: 44.5590 - val_loss: 36.2634 - 42ms/epoch - 4ms/step\n",
      "Epoch 117/1000\n",
      "10/10 - 0s - loss: 44.0101 - val_loss: 36.1932 - 50ms/epoch - 5ms/step\n",
      "Epoch 118/1000\n",
      "10/10 - 0s - loss: 44.5253 - val_loss: 36.1185 - 55ms/epoch - 6ms/step\n",
      "Epoch 119/1000\n",
      "10/10 - 0s - loss: 43.6802 - val_loss: 35.3576 - 49ms/epoch - 5ms/step\n",
      "Epoch 120/1000\n",
      "10/10 - 0s - loss: 43.8521 - val_loss: 35.2081 - 63ms/epoch - 6ms/step\n",
      "Epoch 121/1000\n",
      "10/10 - 0s - loss: 42.8944 - val_loss: 35.2362 - 63ms/epoch - 6ms/step\n",
      "Epoch 122/1000\n",
      "10/10 - 0s - loss: 43.0618 - val_loss: 34.6546 - 46ms/epoch - 5ms/step\n",
      "Epoch 123/1000\n",
      "10/10 - 0s - loss: 42.5577 - val_loss: 34.5727 - 46ms/epoch - 5ms/step\n",
      "Epoch 124/1000\n",
      "10/10 - 0s - loss: 42.0112 - val_loss: 35.2444 - 47ms/epoch - 5ms/step\n",
      "Epoch 125/1000\n",
      "10/10 - 0s - loss: 41.5351 - val_loss: 33.8780 - 50ms/epoch - 5ms/step\n",
      "Epoch 126/1000\n",
      "10/10 - 0s - loss: 43.1731 - val_loss: 36.7196 - 42ms/epoch - 4ms/step\n",
      "Epoch 127/1000\n",
      "10/10 - 0s - loss: 44.9588 - val_loss: 34.4649 - 67ms/epoch - 7ms/step\n",
      "Epoch 128/1000\n",
      "10/10 - 0s - loss: 41.6290 - val_loss: 35.5199 - 74ms/epoch - 7ms/step\n",
      "Epoch 129/1000\n",
      "10/10 - 0s - loss: 40.7516 - val_loss: 33.2187 - 43ms/epoch - 4ms/step\n",
      "Epoch 130/1000\n",
      "10/10 - 0s - loss: 42.1431 - val_loss: 35.9299 - 65ms/epoch - 6ms/step\n",
      "Epoch 131/1000\n",
      "10/10 - 0s - loss: 40.5715 - val_loss: 32.7406 - 45ms/epoch - 4ms/step\n",
      "Epoch 132/1000\n",
      "10/10 - 0s - loss: 40.3439 - val_loss: 32.6067 - 71ms/epoch - 7ms/step\n",
      "Epoch 133/1000\n",
      "10/10 - 0s - loss: 39.9940 - val_loss: 32.7292 - 47ms/epoch - 5ms/step\n",
      "Epoch 134/1000\n",
      "10/10 - 0s - loss: 40.0634 - val_loss: 32.1410 - 48ms/epoch - 5ms/step\n",
      "Epoch 135/1000\n",
      "10/10 - 0s - loss: 40.4516 - val_loss: 32.3407 - 69ms/epoch - 7ms/step\n",
      "Epoch 136/1000\n",
      "10/10 - 0s - loss: 39.1197 - val_loss: 32.0680 - 61ms/epoch - 6ms/step\n",
      "Epoch 137/1000\n",
      "10/10 - 0s - loss: 38.6692 - val_loss: 31.8778 - 51ms/epoch - 5ms/step\n",
      "Epoch 138/1000\n",
      "10/10 - 0s - loss: 38.7935 - val_loss: 32.9095 - 59ms/epoch - 6ms/step\n",
      "Epoch 139/1000\n",
      "10/10 - 0s - loss: 38.6567 - val_loss: 31.1871 - 54ms/epoch - 5ms/step\n",
      "Epoch 140/1000\n",
      "10/10 - 0s - loss: 38.1735 - val_loss: 31.1331 - 63ms/epoch - 6ms/step\n",
      "Epoch 141/1000\n",
      "10/10 - 0s - loss: 37.6601 - val_loss: 31.2389 - 44ms/epoch - 4ms/step\n",
      "Epoch 142/1000\n",
      "10/10 - 0s - loss: 37.5095 - val_loss: 31.1678 - 62ms/epoch - 6ms/step\n",
      "Epoch 143/1000\n",
      "10/10 - 0s - loss: 37.3672 - val_loss: 30.4313 - 61ms/epoch - 6ms/step\n",
      "Epoch 144/1000\n",
      "10/10 - 0s - loss: 37.9671 - val_loss: 30.2334 - 50ms/epoch - 5ms/step\n",
      "Epoch 145/1000\n",
      "10/10 - 0s - loss: 37.7869 - val_loss: 32.6676 - 61ms/epoch - 6ms/step\n",
      "Epoch 146/1000\n",
      "10/10 - 0s - loss: 37.3247 - val_loss: 30.0956 - 49ms/epoch - 5ms/step\n",
      "Epoch 147/1000\n",
      "10/10 - 0s - loss: 37.0411 - val_loss: 29.7544 - 63ms/epoch - 6ms/step\n",
      "Epoch 148/1000\n",
      "10/10 - 0s - loss: 37.8974 - val_loss: 34.1898 - 55ms/epoch - 6ms/step\n",
      "Epoch 149/1000\n",
      "10/10 - 0s - loss: 35.6341 - val_loss: 31.0651 - 50ms/epoch - 5ms/step\n",
      "Epoch 150/1000\n",
      "10/10 - 0s - loss: 38.9956 - val_loss: 32.1005 - 52ms/epoch - 5ms/step\n",
      "Epoch 151/1000\n",
      "10/10 - 0s - loss: 35.7875 - val_loss: 28.9734 - 65ms/epoch - 7ms/step\n",
      "Epoch 152/1000\n",
      "10/10 - 0s - loss: 35.7318 - val_loss: 29.1119 - 48ms/epoch - 5ms/step\n",
      "Epoch 153/1000\n",
      "10/10 - 0s - loss: 35.2600 - val_loss: 28.6848 - 65ms/epoch - 6ms/step\n",
      "Epoch 154/1000\n",
      "10/10 - 0s - loss: 35.9957 - val_loss: 29.1977 - 42ms/epoch - 4ms/step\n",
      "Epoch 155/1000\n",
      "10/10 - 0s - loss: 35.7540 - val_loss: 29.7204 - 72ms/epoch - 7ms/step\n",
      "Epoch 156/1000\n",
      "10/10 - 0s - loss: 34.8676 - val_loss: 28.1050 - 44ms/epoch - 4ms/step\n",
      "Epoch 157/1000\n",
      "10/10 - 0s - loss: 34.6044 - val_loss: 29.6049 - 49ms/epoch - 5ms/step\n",
      "Epoch 158/1000\n",
      "10/10 - 0s - loss: 34.8734 - val_loss: 27.8684 - 49ms/epoch - 5ms/step\n",
      "Epoch 159/1000\n",
      "10/10 - 0s - loss: 34.2168 - val_loss: 27.5564 - 61ms/epoch - 6ms/step\n",
      "Epoch 160/1000\n",
      "10/10 - 0s - loss: 34.3384 - val_loss: 27.3708 - 64ms/epoch - 6ms/step\n",
      "Epoch 161/1000\n",
      "10/10 - 0s - loss: 33.9496 - val_loss: 28.5652 - 47ms/epoch - 5ms/step\n",
      "Epoch 162/1000\n",
      "10/10 - 0s - loss: 33.4599 - val_loss: 27.3174 - 58ms/epoch - 6ms/step\n",
      "Epoch 163/1000\n",
      "10/10 - 0s - loss: 33.8438 - val_loss: 27.6048 - 45ms/epoch - 5ms/step\n",
      "Epoch 164/1000\n",
      "10/10 - 0s - loss: 33.1440 - val_loss: 26.6754 - 71ms/epoch - 7ms/step\n",
      "Epoch 165/1000\n",
      "10/10 - 0s - loss: 33.6024 - val_loss: 28.4600 - 45ms/epoch - 4ms/step\n",
      "Epoch 166/1000\n",
      "10/10 - 0s - loss: 33.0155 - val_loss: 26.3480 - 75ms/epoch - 8ms/step\n",
      "Epoch 167/1000\n",
      "10/10 - 0s - loss: 33.6239 - val_loss: 27.4919 - 43ms/epoch - 4ms/step\n",
      "Epoch 168/1000\n",
      "10/10 - 0s - loss: 33.7240 - val_loss: 28.3199 - 51ms/epoch - 5ms/step\n",
      "Epoch 169/1000\n",
      "10/10 - 0s - loss: 33.5670 - val_loss: 25.8991 - 62ms/epoch - 6ms/step\n",
      "Epoch 170/1000\n",
      "10/10 - 0s - loss: 31.7415 - val_loss: 26.0897 - 62ms/epoch - 6ms/step\n",
      "Epoch 171/1000\n",
      "10/10 - 0s - loss: 31.5303 - val_loss: 25.4196 - 49ms/epoch - 5ms/step\n",
      "Epoch 172/1000\n",
      "10/10 - 0s - loss: 31.8498 - val_loss: 26.9220 - 50ms/epoch - 5ms/step\n",
      "Epoch 173/1000\n",
      "10/10 - 0s - loss: 31.6775 - val_loss: 25.7945 - 62ms/epoch - 6ms/step\n",
      "Epoch 174/1000\n",
      "10/10 - 0s - loss: 31.3026 - val_loss: 25.3169 - 53ms/epoch - 5ms/step\n",
      "Epoch 175/1000\n",
      "10/10 - 0s - loss: 30.8672 - val_loss: 25.7407 - 69ms/epoch - 7ms/step\n",
      "Epoch 176/1000\n",
      "10/10 - 0s - loss: 31.5805 - val_loss: 24.5653 - 72ms/epoch - 7ms/step\n",
      "Epoch 177/1000\n",
      "10/10 - 0s - loss: 31.6575 - val_loss: 24.7597 - 53ms/epoch - 5ms/step\n",
      "Epoch 178/1000\n",
      "10/10 - 0s - loss: 31.0366 - val_loss: 26.0440 - 61ms/epoch - 6ms/step\n",
      "Epoch 179/1000\n",
      "10/10 - 0s - loss: 30.4223 - val_loss: 24.2567 - 65ms/epoch - 7ms/step\n",
      "Epoch 180/1000\n",
      "10/10 - 0s - loss: 29.6591 - val_loss: 24.0481 - 62ms/epoch - 6ms/step\n",
      "Epoch 181/1000\n",
      "10/10 - 0s - loss: 29.5555 - val_loss: 23.9970 - 65ms/epoch - 7ms/step\n",
      "Epoch 182/1000\n",
      "10/10 - 0s - loss: 29.4170 - val_loss: 23.5796 - 58ms/epoch - 6ms/step\n",
      "Epoch 183/1000\n",
      "10/10 - 0s - loss: 29.2324 - val_loss: 24.1796 - 52ms/epoch - 5ms/step\n",
      "Epoch 184/1000\n",
      "10/10 - 0s - loss: 28.8220 - val_loss: 23.2315 - 46ms/epoch - 5ms/step\n",
      "Epoch 185/1000\n",
      "10/10 - 0s - loss: 29.0582 - val_loss: 24.1037 - 61ms/epoch - 6ms/step\n",
      "Epoch 186/1000\n",
      "10/10 - 0s - loss: 28.7244 - val_loss: 22.9213 - 64ms/epoch - 6ms/step\n",
      "Epoch 187/1000\n",
      "10/10 - 0s - loss: 28.4226 - val_loss: 23.6453 - 52ms/epoch - 5ms/step\n",
      "Epoch 188/1000\n",
      "10/10 - 0s - loss: 30.4988 - val_loss: 22.3928 - 67ms/epoch - 7ms/step\n",
      "Epoch 189/1000\n",
      "10/10 - 0s - loss: 29.2073 - val_loss: 22.8565 - 46ms/epoch - 5ms/step\n",
      "Epoch 190/1000\n",
      "10/10 - 0s - loss: 27.8428 - val_loss: 24.4894 - 61ms/epoch - 6ms/step\n",
      "Epoch 191/1000\n",
      "10/10 - 0s - loss: 28.7934 - val_loss: 21.9677 - 46ms/epoch - 5ms/step\n",
      "Epoch 192/1000\n",
      "10/10 - 0s - loss: 29.0026 - val_loss: 23.3321 - 68ms/epoch - 7ms/step\n",
      "Epoch 193/1000\n",
      "10/10 - 0s - loss: 28.7747 - val_loss: 21.6816 - 60ms/epoch - 6ms/step\n",
      "Epoch 194/1000\n",
      "10/10 - 0s - loss: 27.4620 - val_loss: 21.3625 - 48ms/epoch - 5ms/step\n",
      "Epoch 195/1000\n",
      "10/10 - 0s - loss: 26.9269 - val_loss: 21.5949 - 46ms/epoch - 5ms/step\n",
      "Epoch 196/1000\n",
      "10/10 - 0s - loss: 27.0653 - val_loss: 21.2440 - 66ms/epoch - 7ms/step\n",
      "Epoch 197/1000\n",
      "10/10 - 0s - loss: 26.5345 - val_loss: 21.7376 - 60ms/epoch - 6ms/step\n",
      "Epoch 198/1000\n",
      "10/10 - 0s - loss: 26.6457 - val_loss: 20.7840 - 43ms/epoch - 4ms/step\n",
      "Epoch 199/1000\n",
      "10/10 - 0s - loss: 26.1900 - val_loss: 20.5610 - 63ms/epoch - 6ms/step\n",
      "Epoch 200/1000\n",
      "10/10 - 0s - loss: 26.4989 - val_loss: 21.2801 - 73ms/epoch - 7ms/step\n",
      "Epoch 201/1000\n",
      "10/10 - 0s - loss: 25.7045 - val_loss: 20.3552 - 51ms/epoch - 5ms/step\n",
      "Epoch 202/1000\n",
      "10/10 - 0s - loss: 26.2127 - val_loss: 20.3249 - 47ms/epoch - 5ms/step\n",
      "Epoch 203/1000\n",
      "10/10 - 0s - loss: 26.5411 - val_loss: 23.3969 - 43ms/epoch - 4ms/step\n",
      "Epoch 204/1000\n",
      "10/10 - 0s - loss: 26.0485 - val_loss: 19.6083 - 52ms/epoch - 5ms/step\n",
      "Epoch 205/1000\n",
      "10/10 - 0s - loss: 25.7512 - val_loss: 21.4974 - 61ms/epoch - 6ms/step\n",
      "Epoch 206/1000\n",
      "10/10 - 0s - loss: 27.9661 - val_loss: 24.6909 - 73ms/epoch - 7ms/step\n",
      "Epoch 207/1000\n",
      "10/10 - 0s - loss: 27.1431 - val_loss: 20.3076 - 41ms/epoch - 4ms/step\n",
      "Epoch 208/1000\n",
      "10/10 - 0s - loss: 25.5981 - val_loss: 20.7630 - 43ms/epoch - 4ms/step\n",
      "Epoch 209/1000\n",
      "10/10 - 0s - loss: 25.4804 - val_loss: 18.8038 - 65ms/epoch - 7ms/step\n",
      "Epoch 210/1000\n",
      "10/10 - 0s - loss: 26.6374 - val_loss: 26.9133 - 63ms/epoch - 6ms/step\n",
      "Epoch 211/1000\n",
      "10/10 - 0s - loss: 26.2150 - val_loss: 18.8805 - 48ms/epoch - 5ms/step\n",
      "Epoch 212/1000\n",
      "10/10 - 0s - loss: 25.7188 - val_loss: 20.6097 - 50ms/epoch - 5ms/step\n",
      "Epoch 213/1000\n",
      "10/10 - 0s - loss: 24.9249 - val_loss: 18.8219 - 50ms/epoch - 5ms/step\n",
      "Epoch 214/1000\n",
      "Restoring model weights from the end of the best epoch: 209.\n",
      "10/10 - 0s - loss: 24.0144 - val_loss: 19.2638 - 50ms/epoch - 5ms/step\n",
      "Epoch 214: early stopping\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<keras.callbacks.History at 0x7f126e090b90>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# HIDE OUTPUT\n",
    "from tensorflow.keras.models import Sequential\n",
    "from tensorflow.keras.layers import Dense, Activation\n",
    "from tensorflow.keras.callbacks import EarlyStopping\n",
    "from sklearn.model_selection import train_test_split\n",
    "import pandas as pd\n",
    "import io\n",
    "import os\n",
    "import requests\n",
    "import numpy as np\n",
    "from sklearn import metrics\n",
    "\n",
    "df = pd.read_csv(\n",
    "    \"https://data.heatonresearch.com/data/t81-558/auto-mpg.csv\", \n",
    "    na_values=['NA', '?'])\n",
    "\n",
    "COLS_USED = ['cylinders', 'displacement', 'horsepower', 'weight', \n",
    "          'acceleration', 'year', 'origin','mpg']\n",
    "COLS_TRAIN = ['cylinders', 'displacement', 'horsepower', 'weight', \n",
    "          'acceleration', 'year', 'origin']\n",
    "\n",
    "df = df[COLS_USED]\n",
    "\n",
    "# Handle missing value\n",
    "df['horsepower'] = df['horsepower'].fillna(df['horsepower'].median())\n",
    "\n",
    "\n",
    "# Split into training and test sets\n",
    "df_x_train, df_x_test, df_y_train, df_y_test = train_test_split(\n",
    "    df.drop(\"mpg\", axis=1),\n",
    "    df[\"mpg\"],\n",
    "    test_size=0.20,\n",
    "    #shuffle=False,\n",
    "    random_state=42,\n",
    ")\n",
    "\n",
    "# Create dataframe versions for tabular GAN\n",
    "df_x_test, df_y_test = df_x_test.reset_index(drop=True), \\\n",
    "  df_y_test.reset_index(drop=True)\n",
    "df_y_train = pd.DataFrame(df_y_train)\n",
    "df_y_test = pd.DataFrame(df_y_test)\n",
    "\n",
    "# Pandas to Numpy\n",
    "x_train = df_x_train.values\n",
    "x_test = df_x_test.values\n",
    "y_train = df_y_train.values\n",
    "y_test = df_y_test.values\n",
    "\n",
    "# Build the neural network\n",
    "model = Sequential()\n",
    "# Hidden 1\n",
    "model.add(Dense(50, input_dim=x_train.shape[1], activation='relu')) \n",
    "model.add(Dense(25, activation='relu')) # Hidden 2\n",
    "model.add(Dense(12, activation='relu')) # Hidden 2\n",
    "model.add(Dense(1)) # Output\n",
    "model.compile(loss='mean_squared_error', optimizer='adam')\n",
    "\n",
    "monitor = EarlyStopping(monitor='val_loss', min_delta=1e-3, \n",
    "        patience=5, verbose=1, mode='auto',\n",
    "        restore_best_weights=True)\n",
    "model.fit(x_train,y_train,validation_data=(x_test,y_test),\n",
    "        callbacks=[monitor], verbose=2,epochs=1000)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "YeR9CQ5weQDB"
   },
   "source": [
    "We now evaluate the trained neural network to see the RMSE. We will use this trained neural network to compare the accuracy between the original data and the GAN-generated data. We will later see that you can use such comparisons for anomaly detection. We can use this technique can be used for security systems. If a neural network trained on original data does not perform well on new data, then the new data may be suspect or fake."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "WFijxBaufVzr",
    "outputId": "1a980286-e40b-4800-becd-cdba31979c8a"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Final score (RMSE): 4.33633936452545\n"
     ]
    }
   ],
   "source": [
    "pred = model.predict(x_test)\n",
    "score = np.sqrt(metrics.mean_squared_error(pred,y_test))\n",
    "print(\"Final score (RMSE): {}\".format(score))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "0k33foL3eTDN"
   },
   "source": [
    "## Training a GAN for Auto MPG\n",
    "\n",
    "Next, we will train the GAN to generate fake data from the original MPG data. There are quite a few options that you can fine-tune for the GAN. The example presented here uses most of the default values. These are the usual hyperparameters that must be tuned for any model and require some experimentation for optimal results. To learn more about tabgab refer to its paper or this [Medium article](https://towardsdatascience.com/review-of-gans-for-tabular-data-a30a2199342), written by the creator of tabgan."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 81,
     "referenced_widgets": [
      "4868c1e7b0c943b594bc1ecad46db436",
      "6ead85f553054e4aa116920a40e49b04",
      "a9f4fb7eacb94aafbf64a98b5fc0fc37",
      "3c26c587accb4c26b0b98221b547356f",
      "39885cd66caa4fe79fc53f2368d7a5c0",
      "5ecaf538dd5744198cedd271a43a6d0f",
      "9030dbab18ec43f481bfc088de9447ec",
      "5dedd3556fd54bf58eef12635398021b",
      "c993e9cdf47c4c6799405a6d628128b4",
      "9972f70113664c92bc38677b63d404f7",
      "6a0f272cb9c249bf8d9a73520988d59a",
      "d778ac7cdd1e4d18b31a2a85d296a1c6",
      "3bb0052560414e108e0e966b36739768",
      "a9ef13d5399a4eb2afee41204ed24c54",
      "7202f83df3894af7add22a1a074617ed",
      "5eb730071b75424ba6a8336a20e10482",
      "e7a881fa8d964ff2ad0a2137cabce76d",
      "3fcd9917617049bd801f1045c5c45448",
      "00b433452b014a2e9fa4b5d70b570bd0",
      "783fede137ea4452a39df668eb12a411",
      "eeb9080176724d6880432f118f359965",
      "a054e62a36cc484e9b1554ed37194876"
     ]
    },
    "id": "L-i4CdwYkgLU",
    "outputId": "599c8605-9570-4436-c3d8-393d88aa2f9f"
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "4868c1e7b0c943b594bc1ecad46db436",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Fitting CTGAN transformers for each column:   0%|          | 0/8 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d778ac7cdd1e4d18b31a2a85d296a1c6",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Training CTGAN, epochs::   0%|          | 0/500 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from tabgan.sampler import GANGenerator\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "gen_x, gen_y = GANGenerator(gen_x_times=1.1, cat_cols=None,\n",
    "           bot_filter_quantile=0.001, top_filter_quantile=0.999, \\\n",
    "              is_post_process=True,\n",
    "           adversarial_model_params={\n",
    "               \"metrics\": \"rmse\", \"max_depth\": 2, \"max_bin\": 100, \n",
    "               \"learning_rate\": 0.02, \"random_state\": \\\n",
    "                42, \"n_estimators\": 500,\n",
    "           }, pregeneration_frac=2, only_generated_data=False,\\\n",
    "           gan_params = {\"batch_size\": 500, \"patience\": 25, \\\n",
    "          \"epochs\" : 500,}).generate_data_pipe(df_x_train, df_y_train,\\\n",
    "          df_x_test, deep_copy=True, only_adversarial=False, \\\n",
    "          use_adversarial=True)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "qBxYegwNdXdz"
   },
   "source": [
    "Note: if you receive an error running the above code, you likely need to restart the runtime. You should have a \"restart runtime\" button in the output from the second cell. Once you restart the runtime, rerun all of the cells. This step is necessary as tabgan requires specific versions of some packages.\n",
    "\n",
    "## Evaluating the GAN Results\n",
    "\n",
    "If we display the results, we can see that the GAN-generated data looks similar to the original. Some values, typically whole numbers in the original data, have fractional values in the synthetic data. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 423
    },
    "id": "CzKROV-Pm1SE",
    "outputId": "2ddf9726-6074-41e6-82bd-a8512f493c5e"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "  <div id=\"df-57379c4d-add7-4e05-b6c5-23fd74fa6236\">\n",
       "    <div class=\"colab-df-container\">\n",
       "      <div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cylinders</th>\n",
       "      <th>displacement</th>\n",
       "      <th>horsepower</th>\n",
       "      <th>weight</th>\n",
       "      <th>acceleration</th>\n",
       "      <th>year</th>\n",
       "      <th>origin</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5</td>\n",
       "      <td>296.949632</td>\n",
       "      <td>106.872450</td>\n",
       "      <td>2133</td>\n",
       "      <td>18.323035</td>\n",
       "      <td>73</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5</td>\n",
       "      <td>247.744505</td>\n",
       "      <td>97.532052</td>\n",
       "      <td>2233</td>\n",
       "      <td>19.490136</td>\n",
       "      <td>75</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>259.648421</td>\n",
       "      <td>108.111921</td>\n",
       "      <td>2424</td>\n",
       "      <td>19.898952</td>\n",
       "      <td>79</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>319.208637</td>\n",
       "      <td>93.764364</td>\n",
       "      <td>2054</td>\n",
       "      <td>19.420225</td>\n",
       "      <td>78</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>386.237667</td>\n",
       "      <td>129.837418</td>\n",
       "      <td>1951</td>\n",
       "      <td>20.989091</td>\n",
       "      <td>82</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>542</th>\n",
       "      <td>8</td>\n",
       "      <td>304.000000</td>\n",
       "      <td>150.000000</td>\n",
       "      <td>3672</td>\n",
       "      <td>11.500000</td>\n",
       "      <td>72</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>543</th>\n",
       "      <td>8</td>\n",
       "      <td>304.000000</td>\n",
       "      <td>150.000000</td>\n",
       "      <td>3433</td>\n",
       "      <td>12.000000</td>\n",
       "      <td>70</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>544</th>\n",
       "      <td>4</td>\n",
       "      <td>98.000000</td>\n",
       "      <td>80.000000</td>\n",
       "      <td>2164</td>\n",
       "      <td>15.000000</td>\n",
       "      <td>72</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>545</th>\n",
       "      <td>4</td>\n",
       "      <td>97.500000</td>\n",
       "      <td>80.000000</td>\n",
       "      <td>2126</td>\n",
       "      <td>17.000000</td>\n",
       "      <td>72</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546</th>\n",
       "      <td>5</td>\n",
       "      <td>138.526374</td>\n",
       "      <td>68.958515</td>\n",
       "      <td>2497</td>\n",
       "      <td>13.495784</td>\n",
       "      <td>71</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>547 rows × 7 columns</p>\n",
       "</div>\n",
       "      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-57379c4d-add7-4e05-b6c5-23fd74fa6236')\"\n",
       "              title=\"Convert this dataframe to an interactive table.\"\n",
       "              style=\"display:none;\">\n",
       "        \n",
       "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
       "       width=\"24px\">\n",
       "    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
       "    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
       "  </svg>\n",
       "      </button>\n",
       "      \n",
       "  <style>\n",
       "    .colab-df-container {\n",
       "      display:flex;\n",
       "      flex-wrap:wrap;\n",
       "      gap: 12px;\n",
       "    }\n",
       "\n",
       "    .colab-df-convert {\n",
       "      background-color: #E8F0FE;\n",
       "      border: none;\n",
       "      border-radius: 50%;\n",
       "      cursor: pointer;\n",
       "      display: none;\n",
       "      fill: #1967D2;\n",
       "      height: 32px;\n",
       "      padding: 0 0 0 0;\n",
       "      width: 32px;\n",
       "    }\n",
       "\n",
       "    .colab-df-convert:hover {\n",
       "      background-color: #E2EBFA;\n",
       "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
       "      fill: #174EA6;\n",
       "    }\n",
       "\n",
       "    [theme=dark] .colab-df-convert {\n",
       "      background-color: #3B4455;\n",
       "      fill: #D2E3FC;\n",
       "    }\n",
       "\n",
       "    [theme=dark] .colab-df-convert:hover {\n",
       "      background-color: #434B5C;\n",
       "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
       "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
       "      fill: #FFFFFF;\n",
       "    }\n",
       "  </style>\n",
       "\n",
       "      <script>\n",
       "        const buttonEl =\n",
       "          document.querySelector('#df-57379c4d-add7-4e05-b6c5-23fd74fa6236 button.colab-df-convert');\n",
       "        buttonEl.style.display =\n",
       "          google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
       "\n",
       "        async function convertToInteractive(key) {\n",
       "          const element = document.querySelector('#df-57379c4d-add7-4e05-b6c5-23fd74fa6236');\n",
       "          const dataTable =\n",
       "            await google.colab.kernel.invokeFunction('convertToInteractive',\n",
       "                                                     [key], {});\n",
       "          if (!dataTable) return;\n",
       "\n",
       "          const docLinkHtml = 'Like what you see? Visit the ' +\n",
       "            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
       "            + ' to learn more about interactive tables.';\n",
       "          element.innerHTML = '';\n",
       "          dataTable['output_type'] = 'display_data';\n",
       "          await google.colab.output.renderOutput(dataTable, element);\n",
       "          const docLink = document.createElement('div');\n",
       "          docLink.innerHTML = docLinkHtml;\n",
       "          element.appendChild(docLink);\n",
       "        }\n",
       "      </script>\n",
       "    </div>\n",
       "  </div>\n",
       "  "
      ],
      "text/plain": [
       "     cylinders  displacement  horsepower  weight  acceleration  year  origin\n",
       "0            5    296.949632  106.872450    2133     18.323035    73       2\n",
       "1            5    247.744505   97.532052    2233     19.490136    75       2\n",
       "2            4    259.648421  108.111921    2424     19.898952    79       3\n",
       "3            5    319.208637   93.764364    2054     19.420225    78       3\n",
       "4            4    386.237667  129.837418    1951     20.989091    82       2\n",
       "..         ...           ...         ...     ...           ...   ...     ...\n",
       "542          8    304.000000  150.000000    3672     11.500000    72       1\n",
       "543          8    304.000000  150.000000    3433     12.000000    70       1\n",
       "544          4     98.000000   80.000000    2164     15.000000    72       1\n",
       "545          4     97.500000   80.000000    2126     17.000000    72       1\n",
       "546          5    138.526374   68.958515    2497     13.495784    71       1\n",
       "\n",
       "[547 rows x 7 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gen_x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "RQ6lc2EHn8i5"
   },
   "source": [
    "Finally, we present the synthetic data to the previously trained neural network to see how accurately we can predict the synthetic targets.  As we can see, you lose some RMSE accuracy by going to synthetic data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "BXoMORyHCU0o",
    "outputId": "21196542-b7e4-4c72-cd47-5f10ec96533b"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Final score (RMSE): 9.083745225633098\n"
     ]
    }
   ],
   "source": [
    "# Predict\n",
    "pred = model.predict(gen_x.values)\n",
    "score = np.sqrt(metrics.mean_squared_error(pred,gen_y.values))\n",
    "print(\"Final score (RMSE): {}\".format(score))"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "colab": {
   "collapsed_sections": [],
   "name": "Copy of Copy of t81_558_class_07_5_tabular_synthetic.ipynb",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3.9 (tensorflow)",
   "language": "python",
   "name": "tensorflow"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "00b433452b014a2e9fa4b5d70b570bd0": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "39885cd66caa4fe79fc53f2368d7a5c0": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "3bb0052560414e108e0e966b36739768": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HTMLModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HTMLModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HTMLView",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_e7a881fa8d964ff2ad0a2137cabce76d",
      "placeholder": "​",
      "style": "IPY_MODEL_3fcd9917617049bd801f1045c5c45448",
      "value": "Training CTGAN, epochs::  17%"
     }
    },
    "3c26c587accb4c26b0b98221b547356f": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HTMLModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HTMLModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HTMLView",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_9972f70113664c92bc38677b63d404f7",
      "placeholder": "​",
      "style": "IPY_MODEL_6a0f272cb9c249bf8d9a73520988d59a",
      "value": " 8/8 [00:02&lt;00:00,  2.87it/s]"
     }
    },
    "3fcd9917617049bd801f1045c5c45448": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "4868c1e7b0c943b594bc1ecad46db436": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HBoxModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HBoxModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HBoxView",
      "box_style": "",
      "children": [
       "IPY_MODEL_6ead85f553054e4aa116920a40e49b04",
       "IPY_MODEL_a9f4fb7eacb94aafbf64a98b5fc0fc37",
       "IPY_MODEL_3c26c587accb4c26b0b98221b547356f"
      ],
      "layout": "IPY_MODEL_39885cd66caa4fe79fc53f2368d7a5c0"
     }
    },
    "5dedd3556fd54bf58eef12635398021b": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "5eb730071b75424ba6a8336a20e10482": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "5ecaf538dd5744198cedd271a43a6d0f": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "6a0f272cb9c249bf8d9a73520988d59a": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "6ead85f553054e4aa116920a40e49b04": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HTMLModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HTMLModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HTMLView",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_5ecaf538dd5744198cedd271a43a6d0f",
      "placeholder": "​",
      "style": "IPY_MODEL_9030dbab18ec43f481bfc088de9447ec",
      "value": "Fitting CTGAN transformers for each column: 100%"
     }
    },
    "7202f83df3894af7add22a1a074617ed": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HTMLModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HTMLModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HTMLView",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_eeb9080176724d6880432f118f359965",
      "placeholder": "​",
      "style": "IPY_MODEL_a054e62a36cc484e9b1554ed37194876",
      "value": " 87/500 [00:15&lt;00:57,  7.13it/s]"
     }
    },
    "783fede137ea4452a39df668eb12a411": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "ProgressStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "ProgressStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "bar_color": null,
      "description_width": ""
     }
    },
    "9030dbab18ec43f481bfc088de9447ec": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "9972f70113664c92bc38677b63d404f7": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "a054e62a36cc484e9b1554ed37194876": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "a9ef13d5399a4eb2afee41204ed24c54": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "FloatProgressModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "FloatProgressModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "ProgressView",
      "bar_style": "danger",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_00b433452b014a2e9fa4b5d70b570bd0",
      "max": 500,
      "min": 0,
      "orientation": "horizontal",
      "style": "IPY_MODEL_783fede137ea4452a39df668eb12a411",
      "value": 87
     }
    },
    "a9f4fb7eacb94aafbf64a98b5fc0fc37": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "FloatProgressModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "FloatProgressModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "ProgressView",
      "bar_style": "success",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_5dedd3556fd54bf58eef12635398021b",
      "max": 8,
      "min": 0,
      "orientation": "horizontal",
      "style": "IPY_MODEL_c993e9cdf47c4c6799405a6d628128b4",
      "value": 8
     }
    },
    "c993e9cdf47c4c6799405a6d628128b4": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "ProgressStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "ProgressStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "bar_color": null,
      "description_width": ""
     }
    },
    "d778ac7cdd1e4d18b31a2a85d296a1c6": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HBoxModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HBoxModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HBoxView",
      "box_style": "",
      "children": [
       "IPY_MODEL_3bb0052560414e108e0e966b36739768",
       "IPY_MODEL_a9ef13d5399a4eb2afee41204ed24c54",
       "IPY_MODEL_7202f83df3894af7add22a1a074617ed"
      ],
      "layout": "IPY_MODEL_5eb730071b75424ba6a8336a20e10482"
     }
    },
    "e7a881fa8d964ff2ad0a2137cabce76d": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "eeb9080176724d6880432f118f359965": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    }
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
